//
//  TotalPriceView.m
//  EasyToTesco
//
//  Created by mc on 16/2/19.
//  Copyright © 2016年 Jack. All rights reserved.
//

#import "TotalPriceView.h"
#import "HeaderFileForEasyToTesco.h"

#define TEXTFONT 16
#define Marc 5
@interface TotalPriceView()
{
    UILabel *headerLabel;
}

@end

@implementation TotalPriceView
-(instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addTotalViews];
    }
    return self;
}

- (void)addTotalViews {
    headerLabel = [[UILabel alloc] init];
    headerLabel.font = [UIFont systemFontOfSize:TEXTFONT];
    headerLabel.text = @"合计 : ";
    headerLabel.textAlignment = NSTextAlignmentCenter;
    headerLabel.textColor = [UIColor blackColor];
    [self addSubview:headerLabel];
    
    self.priceLabel = [[UILabel alloc] init];
    self.priceLabel.textColor = [UIColor redColor];
    self.priceLabel.font = [UIFont systemFontOfSize:TEXTFONT];
    self.priceLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.priceLabel];
    
    self.transLabel = [[UILabel alloc] init];
    self.transLabel.text = @"不含运费";
    self.transLabel.textColor = [UIColor blackColor];
    self.transLabel.textAlignment = NSTextAlignmentCenter;
    self.transLabel.font = [UIFont systemFontOfSize:TEXTFONT];
    [self addSubview:self.transLabel];
    
    self.userInteractionEnabled = YES;
}

- (CGFloat)returnRect:(UILabel *)label {
    CGRect tmpRect = [label.text boundingRectWithSize:CGSizeMake(self.frame.size.width, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:label.font,NSFontAttributeName, nil] context:nil];
    return tmpRect.size.width;
    
}
- (void)layoutSubviews {
    [super layoutSubviews];
    
    headerLabel.frame = CGRectMake(Marc, Marc, [self returnRect:headerLabel], CGRectGetHeight(self.bounds) - Marc*2);
    self.transLabel.frame = CGRectMake(CGRectGetWidth(self.bounds)-[self returnRect:self.transLabel]-Marc, Marc, [self returnRect:self.transLabel], CGRectGetHeight(self.bounds) - Marc*2);
    self.priceLabel.frame = CGRectMake(CGRectGetMaxX(headerLabel.frame), Marc, CGRectGetWidth(self.frame)-CGRectGetWidth(self.transLabel.frame)-CGRectGetWidth(headerLabel.frame)-Marc*2, CGRectGetHeight(self.bounds) - Marc*2);
    NSLog(@"%lf,,,,%lf....%lf", headerLabel.frame.size.width, self.priceLabel.frame.size.width, self.transLabel.frame.size.width);
}
@end
